package com.sina.common.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sina.common.R;
import com.sina.common.base.BaseDialog;


/**
 * 银行卡选择器
 */
public class BankCardSelectorDialog extends BaseDialog {

    private TextView mTvTitle;
    private TextView mTvMessage;
    private TextView mTvCardNumber;

    private TextView mTvNegative;
    private TextView mTvPositive;

    private BankCardSelectorDialog(Context context, boolean defaultOrder) {
        super(context, R.layout.dialog_bankcard_selector, defaultOrder);
    }

    public static BankCardSelectorDialog create(Context context) {
        return create(context, true);
    }

    public static BankCardSelectorDialog create(Context context, boolean defaultOrder) {
        return new BankCardSelectorDialog(context, defaultOrder);
    }

    @Override
    protected void initView() {
        mTvTitle = mDialog.findViewById(R.id.tv_title);
        mTvMessage = mDialog.findViewById(R.id.tv_message);
        mTvCardNumber = mDialog.findViewById(R.id.tv_card_number);
        mTvNegative = mDialog.findViewById(R.id.tv_negative);
        mTvPositive = mDialog.findViewById(R.id.tv_positive);
    }

    @Override
    protected void defaultView() {
        mTvNegative.setOnClickListener(this);
        mTvPositive.setOnClickListener(this);
    }

    @Override
    public BankCardSelectorDialog setTitle(String title) {
        if(!TextUtils.isEmpty(title)) {
            mTvTitle.setText(title);
        }
        return this;
    }

    @Override
    public BankCardSelectorDialog setMessage(String message) {
        if(!TextUtils.isEmpty(message)) {
            mTvMessage.setText(message);
        }
        return this;
    }

    public BankCardSelectorDialog setCardNumber(String cardNumber) {
        if(!TextUtils.isEmpty(cardNumber)) {
            mTvCardNumber.setText(cardNumber);
        }
        return this;
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.tv_negative) {
            onNegative(v);
            mDialog.dismiss();
        } else if (i == R.id.tv_positive) {
            onPositive(v);
            mDialog.dismiss();
        }
    }
}
